package com.yaoxuguang.concurrence.mic;

import java.util.concurrent.TimeUnit;

/**
 * @author yaoxuguang
 * @Title: yao-interview
 * @Package com.yaoxuguang.concurrence
 * @Description: 利用volatile在线程之间的可见性中止线程
 * @date 2018年12月14日16:30
 */
public class VolatileDemo {
    private static volatile boolean flag = false;
    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(()->{
            int i = 0;
            while (!flag){
                i++;
                System.out.println("Num:"+i);
            }
        },"volatile");
        thread.start();
        System.out.println("begin threadBase start...");
        TimeUnit.SECONDS.sleep(1);
        flag = true;
    }
}
